<?php


namespace App\Console\Crawle;

use GuzzleHttp\Client;
abstract class Grab
{
    protected $client;

    protected $pseudo = [
        '/product|/goods','其實|實際','怎麼樣|如何','關於它|有關它','另外|此外','每天|每日','防止|預防'
    ];

    public function __construct()
    {
        $this->client = new Client();
    }

    public function Pseudo($data = []){
        $this->pseudo = $data;
        return $this;
    }

    public function run(){
        $urls = $this->getArticleLinks();
        $contents = [];
        foreach($urls as $url){
            $contents = $this->getArticleContent($url);
            foreach($this->pseudo as $pseudo){
                $contents['title'] = str_replace($pseudo['search'],$pseudo['replace'],$contents['tittle']);
                $contents['content'] = str_replace($pseudo['search'],$pseudo['replace'],$contents['content']);
            }
        }
        return $contents;

    }

    abstract protected function getArticleLinks();

    abstract protected function getArticleContent($url);
}
